package Managers;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.opensymphony.xwork2.ActionSupport;


public class MyFileManager extends ActionSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MyFileManager(){
		
	}
	
	public boolean write(String txt, String path, boolean add){
		try {  
			  //write converted json data to a file named "CountryGSON.json"
			  FileWriter writer = new FileWriter(path,add);
			  
			  writer.write(txt);  
			  writer.close();  
			    
			} catch (IOException e) {  
				 e.printStackTrace();
				 return false;
			} 
		
		return true;
	}
	
	public String read(String path){
		
		String result = "";
		try {
			InputStream i_s = new FileInputStream(path);
		
			String resultString = IOUtils.toString(i_s, null);
	   		result = resultString;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
		
	}

}
